﻿<%@ WebHandler Language="C#" Class="ZSYearTargetDetail" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.SessionState;
using System.IO;
using ReportBusiness;

public class ZSYearTargetDetail : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private uMESReportOracleDAL dal = new uMESReportOracleDAL();
    public void ProcessRequest(HttpContext context)
    {
        if (context.Request.Form["type"] != null && context.Request.Form["type"] == "GetData")
        {
            Dictionary<string, string> para = new Dictionary<string, string>();
            if (context.Request.Form["page"] != null)
            {
                para["page"] = context.Request.Form["page"].ToString();
            }
            if (context.Request.Form["rows"] != null)
            {
                para["rows"] = context.Request.Form["rows"].ToString();
            }
            //月份
            if (context.Request.Form["month"] != null)
            {
                para["month"] = context.Request.Form["month"].ToString().Substring(0, 2);
            }
            //sqcdp类型
            if (context.Request.Form["sqcdptype"] != null)
            {
                para["sqcdptype"] = context.Request.Form["sqcdptype"].ToString().ToUpper().Substring(0, 1);
            }

            int pageCount = 0;
            int rowCount = 0;

            string sql = @"
SELECT DECODE(yp.sqcdptype,0,'S',1,'Q',2,'C',3,'D',4,'P') sqcdptype,
       SUBSTR(yp.yearmonth,5,2) || '月' yearmonth,
       yp.planqty,yp.completeqty,yp.planqty - yp.completeqty notfinishqty,yp.notes
FROM yearmonth_sqcdp_plan yp
LEFT JOIN factory f ON f.factoryid = yp.factoryid
WHERE f.factoryname = '发动机总体事业部'
      AND SUBSTR(yp.yearmonth,0,4) = to_char(SYSDATE,'yyyy')
";

            sql += string.Format(" AND SUBSTR(yp.yearmonth,5,2) = '{0}' ", para["month"].ToString());
            sql += string.Format(" AND DECODE(yp.sqcdptype,0,'S',1,'Q',2,'C',3,'D',4,'P') = '{0}' ", para["sqcdptype"].ToString());

            uMESPagingDataDTO retR = dal.GetPagingDataIns(sql, Convert.ToInt32(para["page"]), Convert.ToInt32(para["rows"]));
            pageCount = Convert.ToInt32(retR.PageCount);
            rowCount = Convert.ToInt32(retR.RowCount);

            var json = JsonConvert.SerializeObject(retR.DBTable);
            context.Response.ContentType = "text/json";
            json = "{\"data\":" + json.ToString()
                    + ",\"count\":" + rowCount
                    + ",\"code\":" + "0"
                    + ",\"msg\":" + "0"
                    + "}";
            context.Response.Write(json.ToString());
            context.Response.End();
        }
    }
}